/*
 * MatrixPositionAndClockComparator.h
 *
 *  Created on: Oct 15, 2012
 *      Author: lfelipe
 */

#ifndef MATRIXPOSITIONANDCLOCKCOMPARATOR_H_
#define MATRIXPOSITIONANDCLOCKCOMPARATOR_H_

#include "LayerComparator.h"

class MatrixPositionAndClockComparator: public LayerComparator
{
public:
    MatrixPositionAndClockComparator(){}
    virtual ~MatrixPositionAndClockComparator(){}

    virtual double compare(Layer & a, Layer & b){
        double distance =0;
    //    std::vector<short int> fixed_cells = std::vector<short int>(a.number_of_cells());
        for (int i = 0; i < a.grid_size_x(); ++i) {
            for (int j = 0; j < a.grid_size_y(); ++j) {
                Cell * a_cell = a.get_cell_at_position(i,j);
                Cell * b_cell = b.get_cell_at_position(i,j);
                if( a_cell != NULL)
                {
                    if(b_cell != NULL) {
                        if(a_cell->cell_id() == b_cell->cell_id()) {
                            if(a_cell->cell_clock_zone() != b_cell->cell_clock_zone()){
                                distance++;
                            }
                        }else
                        {
                            distance++;
                        }
                    } else {
                        distance++;
                    }
                }
            }
        }
        return (distance==0)?0:(distance/(a.grid_size_x()*a.grid_size_y()));
    }
};

#endif /* MATRIXPOSITIONANDCLOCKCOMPARATOR_H_ */
